package com.qdu.service.impl;

import com.qdu.bean.Task;
import com.qdu.mapper.TaskMapper;
import com.qdu.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskServiceIml implements TaskService {

    @Autowired
    TaskMapper taskMapper;

    @Override
    public void makeTask(List<Task> taskList, String company) {
        for (Task task:taskList
             ) {
            task.setCompany(company);
            taskMapper.makeTask(task);
        }
    }

    @Override
    public boolean checkTask(String company) {
        List<Task> taskList = taskMapper.checkTask(company);
        int count = 0;
        for (Task task:taskList
             ) {
            if (count== (taskList.size()-1)) {
                if (task.getIsfinish() == 0) {
                    return false;
                }
                return true;
            }
            count++;
        }

        return true;
    }

    @Override
    public List<Task> showService(String company) {
        return taskMapper.checkTask(company);
    }

    @Override
    public void doneTask(String id) {
        taskMapper.doneTask(id);
    }

    @Override
    public void doneAllTask(String company) {
        taskMapper.doneAllTask(company);
    }

}
